package com.xishu.service.print.kitchen;

import com.xishu.entity.order.Order;
import com.xishu.entity.order.OrderItem;
import com.xishu.util.Tools;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 打印一菜一单里面的每一项
 */
public class PrinterOrderItemCmd implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(PrinterOrderItemCmd.class);
    private Order printerOrder;
    private OrderItem orderItem;

    public PrinterOrderItemCmd(Order printerOrder) {
        this.printerOrder = printerOrder;
    }

    @Override
    public boolean execute(Context context) throws Exception {
        Order oneItemOneOrder = new Order();
        BeanUtils.copyProperties(printerOrder, oneItemOneOrder);

        List<OrderItem> orderItemList = new ArrayList<>();
        orderItemList.add(orderItem);
        oneItemOneOrder.setOrderItemDetailList(orderItemList);

        logger.info("will print order item is {}, itemId {}", orderItem.getId(), orderItem.getItemId());

        //有几份就打印几次
        for (Integer i = 0; i < orderItem.getCount(); i++) {
            //依次打印
//            printOneOrderWhenSendToKitchen(orderInDb, oneItemOneOrder, kitchenPrinter);
        }
        return false;
    }
}
